
<div id="myheader">
<?php
session_start();
?>
</div>
<head>
 
  <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<link rel="stylesheet" href="style/ospms.css" type="text/css">
  <script language="JavaScript" type="text/javascript" src="js/jquery.js"></script>
  <script language="JavaScript" type="text/javascript" src="js/ospms.js"></script>
<style type="text/css" media="all">
#project_list{ text-align:left; overflow:auto;height:100%;}
.table_study{border: 1px solid #e0e0e0; width:95%; };
.div_study{ width:100%;padding-left:30px;};
</style>

</head>
<div id="subMain" >
<?php
include "include/dbConfig.php";
try {
	
	$conn = new PDO("mysql:host=$dbservername;dbname=$dbname", $dbusername, $dbpassword);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$user_id = $_SESSION['user_id'];
	$query = "SELECT project_name,project_description FROM user_projects where user_id = ". $user_id;
	$stmt = $conn->prepare($query);
	$stmt->execute();
	// set the resulting array to associative
	$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
	$array_project = $stmt->fetchAll();
	//var_dump($array_project);

	$query = "SELECT study_name,study_description,project_id,study_id FROM user_studies where user_id = " .$user_id. " and project_id = 1";
	$stmt = $conn->prepare($query);
	$stmt->execute();
	// set the resulting array to associative
	$result = $stmt->setFetchMode(PDO::FETCH_ASSOC);
	$array_study = $stmt->fetchAll();
	//var_dump($array_study);
	$dsn = null;
	echo '<div id="project_list">';
	foreach ($array_project as $key => $value) {
		echo "<div class='project'><div class='TitleH1'>".$value["project_name"]."</div>";
		echo "<div class='ContentH1'>".$value["project_description"]."</div>";
		$sub_prj = $value;
		$num=0;
		echo "<div class='div_study'><table class='table_study'>";
		foreach($array_study as $substudy => $substudy_item)
		{
			$num++;
			echo "<tr><td>";
			if($num%2==1)
				echo "<div class='tableData'>";
			else 
				echo "<div class='tableData2'>";
			echo "<div class='TitleH2'>". $substudy_item['study_name']." &nbsp;<a href='javascript:void()' name='' onclick=\"openFolder('". $substudy_item['project_id']."','". $substudy_item['study_id']."')\" type='button' >Folder</a> &nbsp;<a href='javascript:void()' name='' type='button' onclick=\"function openProgram('". $substudy_item['project_id']."','". $substudy_item['study_id']."')\" >Program</a> &nbsp;<a href='javascript:void()'  name='' type='button' onclick=\"openOutput('". $substudy_item['project_id']."','". $substudy_item['study_id']."')\" >Output</a>  </div>";
			echo "<div class='ContentH2'>". $substudy_item['study_description']."</div>";
			echo "</div>";
			echo "</td></tr>";
			
		}
		echo "</table></div>";
		echo "</div>". " \n";
	}
	echo "</div>";
}

catch(PDOException $e)
{
	echo "Error: " . $e->getMessage();
} // try - catch
$conn = null;
?> 

</div>
</div>
<script>
function openFolder(pid,sid)
{
	window.location.href="/OSPMS/Folder/ShowFolder.php?project_id="+pid+"&study_id="+sid;
}
function openProgram(pid,sid)
{
//	window.location.href="/OSPMS/Program/ShowProgram.php?project_id="+pid+"&study_id="+sid;
	window.location.href="/OSPMS/Program/ShowProgram-new.php?project_id="+pid+"&study_id="+sid;
}
function openOutput(pid,sid)
{
//	window.location.href="/OSPMS/Program/ShowProgramOutput.php?project_id="+pid+"&study_id="+sid;
	window.location.href="/OSPMS/Program/ShowProgram-new.php?project_id="+pid+"&study_id="+sid;
}
</script>
